from qaml import Circuit

# Create a circuit that is composed of two numbers with 3 bits of
# precision. Since we know the answer will be less than 1, we can
# place all of the precision on the fractional side of the decimal.
num_bits = 3
c = Circuit()
a = c.Number(num_bits, exponent=-num_bits, signed=False)
b = c.Number(num_bits, exponent=-num_bits, signed=False)

# Add polynomial equations to the circuit for a circle and a x=y line.
c.add( a**2 + b**2 - 1 )
c.add( a - b )

# Assemble the equations into a least squares energy function and
# execute using the default system (a brute-force exhaustive search).
q = c.run(min_only=False)


#                         SAMPLE OUTPUT
# ____________________________________________________________________
# 
#
# Using and strength 0.05.
#
#  QUBO with 12 bits in range [-0.375, 0.328125].
#    {'a12': -0.09375, 'b4b6': 0.1796875, 'b4b12': -0.08984375, 'b6b12': -0.03125, 'a11': 0.01953125, 'b4b5': 0.111328125, 'b4b11': -0.091796875, 'b5b11': -0.0859375, 'a10': -0.296875, 'b5b6': 0.328125, 'b5b10': -0.0625, 'b6b10': 0.03125, 'a9': -0.296875, 'b2b3': 0.328125, 'b2b9': -0.0625, 'b3b9': 0.03125, 'a8': -0.09375, 'b1b3': 0.1796875, 'b1b8': -0.08984375, 'b3b8': -0.03125, 'a7': 0.01953125, 'b1b2': 0.111328125, 'b1b7': -0.091796875, 'b2b7': -0.0859375, 'a1': -0.015380859375, 'a2': -0.05859375, 'a3': -0.1875, 'a4': -0.015380859375, 'a5': -0.05859375, 'a6': -0.1875, 'b1b4': -0.03076171875, 'b1b5': -0.060546875, 'b1b6': -0.1171875, 'b2b4': -0.060546875, 'b2b5': -0.1171875, 'b2b6': -0.21875, 'b3b4': -0.1171875, 'b3b5': -0.21875, 'b3b6': -0.375, 'c': 1, 'b1b9': 0.0078125, 'b1b10': 0.0078125, 'b1b11': 0.001953125, 'b1b12': 0.00390625, 'b2b8': 0.015625, 'b2b10': 0.03125, 'b2b11': 0.0078125, 'b2b12': 0.015625, 'b3b7': 0.03125, 'b3b10': 0.125, 'b3b11': 0.03125, 'b3b12': 0.0625, 'b4b7': 0.001953125, 'b4b8': 0.00390625, 'b4b9': 0.0078125, 'b4b10': 0.0078125, 'b5b7': 0.0078125, 'b5b8': 0.015625, 'b5b9': 0.03125, 'b5b12': 0.015625, 'b6b7': 0.03125, 'b6b8': 0.0625, 'b6b9': 0.125, 'b6b11': 0.03125, 'b7b8': 0.015625, 'b7b9': 0.03125, 'b7b10': 0.03125, 'b7b11': 0.0078125, 'b7b12': 0.015625, 'b8b9': 0.0625, 'b8b10': 0.0625, 'b8b11': 0.015625, 'b8b12': 0.03125, 'b9b10': 0.125, 'b9b11': 0.03125, 'b9b12': 0.0625, 'b10b11': 0.03125, 'b10b12': 0.0625, 'b11b12': 0.015625}
#  ------------------------------------------------------------------------------------
#   -0.02
#    0.11  -0.06
#    0.18   0.33  -0.19
#   -0.03  -0.06  -0.12  -0.02
#   -0.06  -0.12  -0.22   0.11  -0.06
#   -0.12  -0.22  -0.38   0.18   0.33  -0.19
#   -0.09  -0.09   0.03   0.00   0.01   0.03   0.02
#   -0.09   0.02  -0.03   0.00   0.02   0.06   0.02  -0.09
#    0.01  -0.06   0.03   0.01   0.03   0.12   0.03   0.06  -0.30
#    0.01   0.03   0.12   0.01  -0.06   0.03   0.03   0.06   0.12  -0.30
#    0.00   0.01   0.03  -0.09  -0.09   0.03   0.01   0.02   0.03   0.03   0.02
#    0.00   0.02   0.06  -0.09   0.02  -0.03   0.02   0.03   0.06   0.06   0.02  -0.09
#  ------------------------------------------------------------------------------------
#
# a     	b     	and breaks	Energy         	
#   0.75	  0.75	     50.0%	       0.015625	
#  0.625	  0.75	     50.0%	 0.017822265625	
#   0.75	 0.625	     50.0%	 0.017822265625	
#  0.625	 0.625	     50.0%	   0.0478515625	
#  0.625	 0.875	     50.0%	   0.0869140625	
#  0.875	 0.625	     50.0%	   0.0869140625	
#    0.5	  0.75	     50.0%	     0.09765625	
#   0.75	   0.5	     50.0%	     0.09765625	
#   0.75	 0.875	     50.0%	 0.123291015625	
#  0.875	  0.75	     50.0%	 0.123291015625	
#    0.5	 0.875	     50.0%	 0.140869140625	
#  0.875	   0.5	     50.0%	 0.140869140625	
#    0.5	 0.625	     50.0%	 0.144775390625	
#  0.625	   0.5	     50.0%	 0.144775390625	
#  0.375	  0.75	     50.0%	 0.228759765625	
#   0.75	 0.375	     50.0%	 0.228759765625	
#    0.5	   0.5	     50.0%	           0.25	
#  0.375	 0.875	     50.0%	   0.2587890625	
#  0.875	 0.375	     50.0%	   0.2587890625	
#  0.375	 0.625	     50.0%	   0.2822265625	
#  0.625	 0.375	     50.0%	   0.2822265625	
#  0.875	 0.875	     50.0%	   0.2822265625	
#  0.375	   0.5	     50.0%	 0.386962890625	
#    0.5	 0.375	     50.0%	 0.386962890625	
#   0.25	  0.75	     50.0%	       0.390625	
#   0.75	  0.25	     50.0%	       0.390625	
#   0.25	 0.875	     50.0%	 0.420166015625	
#  0.875	  0.25	     50.0%	 0.420166015625	
#   0.25	 0.625	     50.0%	 0.439697265625	
#  0.625	  0.25	     50.0%	 0.439697265625	
#  0.375	 0.375	     50.0%	   0.5166015625	
#   0.25	   0.5	     50.0%	     0.53515625	
#    0.5	  0.25	     50.0%	     0.53515625	
#  0.125	  0.75	     50.0%	 0.568603515625	
#   0.75	 0.125	     50.0%	 0.568603515625	
#  0.125	 0.625	     50.0%	   0.6025390625	
#  0.625	 0.125	     50.0%	   0.6025390625	
#  0.125	 0.875	     50.0%	   0.6103515625	
#  0.875	 0.125	     50.0%	   0.6103515625	
#   0.25	 0.375	     50.0%	 0.650634765625	
#  0.375	  0.25	     50.0%	 0.650634765625	
#  0.125	   0.5	     50.0%	 0.679931640625	
#    0.5	 0.125	     50.0%	 0.679931640625	
#    0.0	  0.75	     50.0%	     0.75390625	
#   0.75	   0.0	     50.0%	     0.75390625	
#    0.0	 0.625	     50.0%	 0.761962890625	
#  0.625	   0.0	     50.0%	 0.761962890625	
#   0.25	  0.25	     50.0%	       0.765625	
#  0.125	 0.375	     50.0%	   0.7744140625	
#  0.375	 0.125	     50.0%	   0.7744140625	
#    0.0	   0.5	     50.0%	         0.8125	
#    0.5	   0.0	     50.0%	         0.8125	
#    0.0	 0.875	     50.0%	 0.820556640625	
#  0.875	   0.0	     50.0%	 0.820556640625	
#  0.125	  0.25	     50.0%	 0.865478515625	
#   0.25	 0.125	     50.0%	 0.865478515625	
#    0.0	 0.375	     50.0%	 0.879150390625	
#  0.375	   0.0	     50.0%	 0.879150390625	
#  0.125	 0.125	     50.0%	   0.9384765625	
#    0.0	  0.25	     50.0%	     0.94140625	
#   0.25	   0.0	     50.0%	     0.94140625	
#    0.0	 0.125	     50.0%	 0.984619140625	
#  0.125	   0.0	     50.0%	 0.984619140625	
#    0.0	   0.0	     50.0%	            1.0	

